 //===================================销售开单============================== 
$(function(){//
	//===============================1.提交开单信息=======================================
	$('#panel_saleorder').panel({    
		 
		  title: '销售开单``',    
		  tools: [{    
		    iconCls:'icon-add',    
		    handler:function(){alert('new')}    
		  },{    
		    iconCls:'icon-save',    
		    handler:function(){alert('save')}    
		  }]    
		}); 
	
//==================================2.录入商品，显示条目=======================================
	
	$('#grid_saleorderitem').datagrid({    
      url:'showitem.action',   
	 method:'get',
     idField:'saleorderitemid' ,
     singleSelect:true,
     fitColumns:true,
      columns:[[
            {title:'条目编码',
               field:'saleorderitemid',
                 width:100,
                    editor:{
   	              type:'validatebox',
    	         options:{required:true}
                                      }  ,},
            {title:'条目编码',
                field:'saleorderid',
                  width:100,
                     editor:{
    	              type:'validatebox',
     	         options:{required:true}
                     }
                                 },            
                                
                                
           {title:'商品编码',
            field:'productid',
            width:100,         
            },
           
           
            {title:'单价',
                  field:'price',
                  width:100,
                  editor:{
                	  type:'validatebox',
                  	options:{required:true}
                  }  
             },  
             {title:'数量',
                 field:'quantity',
                 width:100,
                 editor:{
                 	type:'validatebox',                   	
                 	options:{required:true}
                 }  
          }
             
            ] ] ,   
    iconCls:'icon-load' ,
    pageSize:10,
    pageList:[3,6,10,15],
    border:false,
    pagination:true,
    sortOrder:'desc',
    sortName:'name',
    editable:true,
    toolbar:[
             {text:'添加',
              iconCls:'icon-add',
              handler: function(){}}]  });//grid结束
	
 
});//
	
//方法定义 
//==1.创建销售单saleorder
function createorder(){
	//打开面板
	 $('#panel1').panel('open');
	//按钮不可点击
	 $('#makeorderbutton').linkbutton('disable');
	// $('#form_saleorder').find('[name=customerid]').disabled=true;
	 document.getElementsByName('customerid')[0].disabled=true;
	 document.getElementsByName('customerid')[0].style.background="transparent";
	 document.getElementsByName('customerid')[0].style.border="none";
	 //style="background:transparent; border:none;" 
	 
	 
	 
	//按钮可点击
	 $('#makeorderbutton').linkbutton('disable');
	 document.getElementsByName('productid')[0].disabled=false;
	 document.getElementsByName('quantity')[0].disabled=false;
	 //document.getElementsByName('productid')[0].style.border="1";
	// document.getElementsByName('quantity')[0].style.border="1";
	 $('#additem').linkbutton('enable');
	 
	
	 $.ajax({
		   url:'addsaleorder.action',
		   data:$('#form_saleorder').serialize(),
		   dataType:'json',
		   success:function(result){
			   if(result&&result.success){
				   $.messager.show({title:'提示',msg:result.msg});
				//   $('#dialog_login').dialog('close');
                  }
			   else
				   {   $.messager.show({title:'提示',msg:result.msg});}}
	 
	   });
	
}
//==2.录入商品，显示条目=====
function createorderitem(){
	 $.ajax({
		   url:'addsaleorderitem.action',
		   data:$('#form_saleorderitem').serialize(),
		   dataType:'json',
		   success:function(result){
			   if(result&&result.success){
				   $.messager.show({title:'提示',msg:result.msg});
				   $('#dialog_login').dialog('close');
                }
			   else
				   {   $.messager.show({title:'提示',msg:result.msg});}}
	   });
	 $('#grid_saleorderitem').datagrid('load',{});
	 $('#amout').form('load','showtotalprice.action');
	 //window.location.reload(true);
}
//==3.结算收银=====
function endsale(){
	alert("haha");
	retail();
	$.ajax({
		url:'endsale.action',
		//data:$('#'),
		dataType:'json',
		   success:function(result){
		if(result&&result.success){
				   $.messager.show({title:'提示',msg:result.msg});
				   $('#dialog_login').dialog('close');
             }
			   else
				   {   $.messager.show({title:'提示',msg:result.msg});}}
	   });
	//window.location.reload(true);
	// $('#grid_saleorderitem').datagrid('load',{});
               }

//=======4.刷新金额
function scrollbottom(){
	
	document.getElementById('test').scrollTop = document.getElementById('test').scrollHeight;
	document.getElementById('test').style.overflow="hidden";
	}
//==========五。找零===============
function retail(){        	 
	 var pay=document.getElementsByName('paymoney')[0].value;
	 
	 var total= document.getElementsByName('total')[0].value;
	 var retailmoney=pay-total;    
	 document.getElementsByName("retailmoney")[0].value=retailmoney;
}
//=======6.挂账=======================
function quitsale(){
	$.ajax({
		url:'quitsale.action',
		//data:$('#'),
		dataType:'json',
		   success:function(result){
		if(result&&result.success){
				   $.messager.show({title:'提示',msg:result.msg});
				  
             }
			   else
				   {   $.messager.show({title:'提示',msg:result.msg});}}
	   });
	// setTimeout("window.location.reload(true);", 10);
	window.location.reload(true);
	
}